<script setup lang="ts">
  import {
    getOrderByID,
  } from '@/services/order'
  import type { OrderCreateParams } from '@/types/order'
  import { onLoad } from '@dcloudio/uni-app'
  import { ref } from 'vue'

  import { useMemberStore } from '@/stores'
  import { useCartStore } from '@/stores/cart'
  import { storeToRefs } from 'pinia'
  const memberStore = useMemberStore()
  const { profile } = storeToRefs(memberStore)
  const cartStore = useCartStore()
  const { cartList, selectedCartListMoney, selectedCartListMoneyWithDiscount, AllPrice } =
    storeToRefs(cartStore)


  // 获取屏幕边界到安全区域距离
  const { safeAreaInsets } = uni.getSystemInfoSync()
  // 页面参数
  // const query = defineProps<{
  //   order_id ?: string
  // }>()
  // console.log(query)
  const orderId = ref<string>()

  onLoad((option : any) => {
    if (option.order_id !== undefined) {
      console.log(option.order_id); //打印出上个页面传递的参数。
      orderId.value = option.order_id
    }
  })



  // 获取订单信息
  const orderPre = ref<OrderCreateParams>()
  const getMemberOrderPreData = async () => {
    const res = await getOrderByID(orderId.value as any)
    orderPre.value = res.result[0]

  }
  onLoad(() => {
    getMemberOrderPreData()

  })
</script>

<template>
  <scroll-view enable-back-to-top scroll-y class="viewport">
    <!-- 收货地址 -->
    <view class="shipment">
      <view class="user"> 当前配送点: </view>
      <view class="address"> {{ profile.addressname }} </view>
    </view>
    <!-- 商品信息 -->
    <view class="goods">
      <view v-for="item in orderPre?.meal_list" :key="item.id" class="item">
        <image class="picture" :src="item.picture" />
        <view class="meta">
          <view class="name ellipsis"> {{ item.name }} </view>
          <view class="attrs">{{ item.mealdesc }}</view>
          <view class="prices">
            <view class="pay-price symbol">{{ item.price }}</view>
            <view class="price symbol">{{ item.price }}</view>
          </view>
          <view class="count">x{{ item.count }}</view>
        </view>
      </view>
    </view>

    <!-- 配送及支付方式 -->
    <view class="related">
      <view class="item">
        <text class="text">送达时间</text>
        <!-- <view class="icon-fonts picker">{{ orderPre?.pstime }}</view> -->
        <view class="icon-fonts picker">{{ '11:50-12:00' }}</view>
      </view>
      <view class="item">
        <text class="text">订单状态</text>
        <text class="input">待配送</text>
      </view>
    </view>

    <!-- 支付金额 -->
    <view class="settlement">
      <view class="item">
        <text class="text">餐品总价: </text>
        <text class="number symbol">{{ AllPrice }}</text>
      </view>
      <view class="item">
        <text class="text">配送费: </text>
        <text class="number symbol">{{ 0.00 }}</text>
      </view>
    </view>
  </scroll-view>
</template>

<style lang="scss">
  page {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background-color: #f4f4f4;
  }

  .symbol::before {
    content: '¥';
    font-size: 80%;
    margin-right: 5rpx;
  }

  .shipment {
    margin: 20rpx;
    padding: 30rpx 30rpx 30rpx 84rpx;
    font-size: 26rpx;
    border-radius: 10rpx;
    background: url(https://pcapi-xiaotuxian-front-devtest.itheima.net/miniapp/images/locate.png) 20rpx center / 50rpx no-repeat #fff;
    position: relative;

    .icon {
      font-size: 36rpx;
      color: #333;
      transform: translateY(-50%);
      position: absolute;
      top: 50%;
      right: 20rpx;
    }

    .user {
      color: #333;
      margin-bottom: 5rpx;
    }

    .address {
      color: #666;
    }
  }

  .goods {
    margin: 20rpx;
    padding: 0 20rpx;
    border-radius: 10rpx;
    background-color: #fff;

    .item {
      display: flex;
      padding: 30rpx 0;
      border-top: 1rpx solid #eee;

      &:first-child {
        border-top: none;
      }

      .picture {
        width: 170rpx;
        height: 170rpx;
        border-radius: 10rpx;
        margin-right: 20rpx;
      }

      .meta {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
        position: relative;
      }

      .name {
        height: 80rpx;
        font-size: 26rpx;
        color: #444;
      }

      .attrs {
        line-height: 1.8;
        padding: 0 15rpx;
        margin-top: 6rpx;
        font-size: 24rpx;
        align-self: flex-start;
        border-radius: 4rpx;
        color: #888;
        background-color: #f7f7f8;
      }

      .prices {
        display: flex;
        align-items: baseline;
        margin-top: 6rpx;
        font-size: 28rpx;

        .pay-price {
          margin-right: 10rpx;
          color: #cf4444;
        }

        .price {
          font-size: 24rpx;
          color: #999;
          text-decoration: line-through;
        }
      }

      .count {
        position: absolute;
        bottom: 0;
        right: 0;
        font-size: 26rpx;
        color: #444;
      }
    }
  }

  .related {
    margin: 20rpx;
    padding: 0 20rpx;
    border-radius: 10rpx;
    background-color: #fff;

    .item {
      display: flex;
      justify-content: space-between;
      align-items: center;
      min-height: 80rpx;
      font-size: 26rpx;
      color: #333;
    }

    .input {
      flex: 1;
      text-align: right;
      margin: 20rpx 0;
      font-size: 26rpx;
      color: #999;
    }

    .item .text {
      width: 125rpx;
    }

    .picker {
      color: #666;
    }
  }

  /* 结算清单 */
  .settlement {
    margin: 20rpx;
    padding: 0 20rpx;
    border-radius: 10rpx;
    background-color: #fff;

    .item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 80rpx;
      font-size: 26rpx;
      color: #333;
    }

    .danger {
      color: #cf4444;
    }
  }

  /* 吸底工具栏 */
  .toolbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--window-bottom));
    z-index: 1;

    background-color: #fff;
    height: 100rpx;
    padding: 0 20rpx;
    border-top: 1rpx solid #eaeaea;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: content-box;

    .total-pay {
      font-size: 40rpx;
      color: #cf4444;

      .decimal {
        font-size: 75%;
      }
    }

    .button {
      width: 220rpx;
      text-align: center;
      line-height: 72rpx;
      font-size: 26rpx;
      color: #fff;
      border-radius: 72rpx;
      background-color: #27ba9b;
    }

    .disabled {
      opacity: 0.6;
    }
  }
</style>
